#-*- coding:utf-8 -*-

import json
from datetime import datetime
from datetime import date

online=False

class ComplexEncoder(json.JSONEncoder):

    def default(self, obj):
        if isinstance(obj, datetime):
            return obj.strftime('%Y-%m-%d %H:%M:%S')
        elif isinstance(obj, date):
            return obj.strftime('%Y-%m-%d')
        else:
            return json.JSONEncoder.default(self, obj)

def json_encode(obj):
    return json.dumps(obj, cls=ComplexEncoder, ensure_ascii=False, indent=2)

def json_decode(jsonStr):
    return json.loads(jsonStr)

#利用生成器表达式将对象列表转换成字典列表，否则无法json序列化
def getDictList(objList):
    return [obj.__dict__ for obj in objList]


